home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-07-27 | 4.0 KB | 171 lines | [TEXT/MPS ] |
- (*****************************************************
- ControlLDEF.p: List Definition Function for list of
- controls.
- *****************************************************)
-
- UNIT ControlLDEF;
-
- INTERFACE
- USES
- {$U MemTypes.p } MemTypes,
- {$U QuickDraw.p } QuickDraw,
- {$U OSIntf.p } OSIntf,
- {$U ToolIntf.p } ToolIntf,
- {$U PackIntf.p } PackIntf,
- {$U PopMenuIntf.p } PopMenuIntf;
-
- PROCEDURE MyLDEF( lMessage: INTEGER;
- lSelect: Boolean;
- lRect: Rect;
- lCell: Cell;
- lDataOffset,
- lDataLen: INTEGER;
- lHandle: ListHandle);
-
- IMPLEMENTATION
- CONST
- isVIS = 255;
- notVIS = 0;
-
- TYPE
- StateStuff = record
- oldPen: PenState;
- oldPort: GrafPtr;
- oldClip: RgnHandle;
- newClip: RgnHandle;
- end; { StateStuff }
-
- PROCEDURE DrawCell(lSelect: Boolean;
- lRect: Rect;
- lCell: Cell;
- lHandle: ListHandle);
- FORWARD;
-
-
-
- (*****************************************************
- MyLDEF: List Definition Function for Controls list.
- Responds to LDrawMsg and lHiliteMsg; ignores
- lInitMsg and lCloseMsg.
- *****************************************************)
-
- PROCEDURE MyLDEF(lMessage: INTEGER;
- lSelect: Boolean;
- lRect: Rect;
- lCell: Cell;
- lDataOffset,
- lDataLen: INTEGER;
- lHandle: ListHandle);
- BEGIN
- CASE lMessage OF
- lInitMsg: ; { no initialization needed }
- lCloseMsg: ; { no deallocation needed }
-
- lDrawMsg, lHiliteMsg:
- DrawCell(lSelect, lRect, lCell, lHandle);
- END; { case }
- END; { MyLDEF }
-
-
- (*****************************************************
- SaveState: Saves the current drawing environment.
- *****************************************************)
-
- PROCEDURE SaveState(VAR oldState: StateStuff;
- lRect: Rect;
- lHandle: ListHandle);
- BEGIN
- WITH oldState DO BEGIN
- { save the current pen state }
- GetPenState(oldPen);
-
- { save current grafPort, set new grafPort }
- GetPort(oldPort);
- SetPort(lHandle^^.port);
-
- { allocate space for old and new clipping regions }
- oldClip := NewRgn;
- newClip := NewRgn;
-
- { save old clipping region }
- GetClip(oldClip);
-
- { set newClip region to given rectangle }
- RectRgn(newClip, lRect);
-
- { intersection of rect and region }
- SectRgn(oldClip, newClip, newClip);
-
- { set grafPorts' clip region to the intersection }
- SetClip(newClip);
- END; { with }
- END; { SaveState }
-
-
- (*****************************************************
- RestoreState: Restores the current drawing environ-
- ment.
- *****************************************************)
-
- PROCEDURE RestoreState(oldState: StateStuff);
- BEGIN
- WITH oldState DO BEGIN
- { restore the previous clipping region }
- SetClip(oldClip);
-
- { restore the previous pen state }
- SetPenState(oldPen);
-
- { restore the previous grafPort }
- SetPort(oldPort);
-
- { dispose of the regions' storage }
- DisposeRgn(oldClip);
- DisposeRgn(newClip);
- END; { with }
- END; { RestoreState }
-
-
- (*****************************************************
- DrawCell: Draws the given cell, either selected or
- normal, by drawing the control stored in the cell.
- *****************************************************)
-
- PROCEDURE DrawCell(lSelect: Boolean;
- lRect: Rect;
- lCell: Cell;
- lHandle: ListHandle);
- VAR
- oldState: StateStuff;
- ch: ControlHandle;
- dl: INTEGER;
-
- BEGIN
- { save the current drawing environment }
- SaveState(oldState, lRect, lHandle);
-
- { get the cell's data }
- dl := sizeof(Handle);
- LGetCell(@ch, dl, lCell, lHandle);
-
- { update the control's fields }
- with ch^^ do begin
- contrlRect := lRect;
- contrlVis := isVIS;
-
- { ensure proper hiliting }
- if (lSelect) then
- contrlHilite := titlePart
- else begin
- contrlHilite := 0;
- end; { if }
- end; { with ch^^ }
-
- { draw the control }
- Draw1Control(ch);
-
- { restore the previous drawing state }
- RestoreState(oldState);
- END; { DrawCell }
-
- END. { ControlLDEF}